﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;

using UsbGuard.Core;

namespace UsbGuard.Server
{
    public  class CService : ServiceBase
    {
        public CService()
        {
            InitializeComponent();
        }


        UsbGuard.Core.Intelligence intel;


        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            System.IO.StreamWriter sw = new StreamWriter("C:\\test\\dienst.txt");
            


            //UsbGuard.Logger.CLog.logger.Debug("Dienst gestartet.");

            string appPath =
               System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            intel = new UsbGuard.Core.Intelligence(null, appPath, false);
            intel.UnregisteredStickRecognized += new UsbGuard.Core.Intelligence.UnregisteredStickRecognizedHandler(intel_UnregisteredStickRecognized);
            
            
            intel.Start();
            Console.ReadKey();


        }

        protected override void OnStop()
        {
            intel.Stop();
        }


        static void intel_UnregisteredStickRecognized()
        {
            string appPath =
                System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            System.Diagnostics.Process.Start(appPath + "\\UsbGuard.Alarm.exe");
        }

    


            /// <summary> 
            /// Erforderliche Designervariable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;

            /// <summary>
            /// Verwendete Ressourcen bereinigen.
            /// </summary>
            /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }

            #region Vom Komponenten-Designer generierter Code

            /// <summary> 
            /// Erforderliche Methode für die Designerunterstützung. 
            /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
            /// </summary>
            private void InitializeComponent()
            {
                components = new System.ComponentModel.Container();
                this.ServiceName = "SService";
            }

            #endregion
        }
    }


